package com.bsj.sipgateway.util.udp;

import com.bsj.tools.netty.UdpServiceUntil;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.net.DatagramPacket;

/**
 * @Description
 * @Author zhaoyang
 * @Date 2024/6/15 15:39
 */
@Slf4j
@Component
public class UdpUntil {

    UdpServiceUntil udpServiceUntil = new UdpServiceUntil();

    public UdpUntil() {
        udpServiceUntil.start(10888, new UdpServerHandler());
        log.info("udp服务启动成功");
    }

    public class UdpServerHandler extends SimpleChannelInboundHandler<DatagramPacket> {

        @Override
        protected void channelRead0(ChannelHandlerContext channelHandlerContext, DatagramPacket datagramPacket) throws Exception {
            byte[] data = datagramPacket.getData();
            log.info("来数据了：");
        }
    }
}
